/******************************************************************************
 * Copyright (c) 2014 - 2016. Danlu.com Co.Ltd. All rights reserved.          *
 ******************************************************************************/

package cn.com.dhc.danlu.widget.couponview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import cn.com.dhc.danlu.R;

/**
 * @author: 李一方
 * @author: 吴海洋
 * @version: 1.0.0
 * @since: 2016-11-07 04:19
 * @mail: liyifang@danlu.com
 * @desc: 经销商红包视图
 */
public class DanluHBView extends BaseDanluCouponView {
    private RedBegView rbView;
    private TextView tvLimit;
    private ImageView ivMarkup;

    public DanluHBView (Context context) {
        super (context);
    }

    public DanluHBView (Context context, AttributeSet attrs) {
        super (context, attrs);
    }

    public DanluHBView (Context context, AttributeSet attrs, int defStyleAttr) {
        super (context, attrs, defStyleAttr);
    }

    @Override
    protected int getViewLayoutId () {
        return R.layout.view_coupon_hb;
    }

    @Override
    protected void initChildView (View root) {
        rbView = (RedBegView) root.findViewById (R.id.rb_view);
        ivMarkup = (ImageView) root.findViewById (R.id.iv_markup);
        tvLimit = (TextView) root.findViewById (R.id.tv_limit);
    }

    @Override
    protected boolean isYhq () {
        return false;
    }

    @Override
    protected void setGetState (CouponGetState state) {
        tvQuota.setPadding (0, getResources ().getDimensionPixelSize (R.dimen.dl_15), 0, 0);
        llRight.setVisibility (VISIBLE);
        switch (state) {
            case getOver:
                svRight.setEnabled (false);
                setActionText ("已\n领\n取");
                rbView.setAvailable (true);
                tvPrice.setEnabled (true);
                tvQuota.setEnabled (true);
                ivUseState.setVisibility (VISIBLE);
                ivUseState.setImageResource (R.drawable.icon_coupon_getover);
                ivLimit.setImageResource (R.drawable.icon_double_arrow_white);
                tvLimit.setEnabled (true);
                setRightActionIsVisible (VISIBLE, GONE);
                setLimitRightPadding (getResources ().getDimensionPixelSize (R.dimen.dl_50));
                break;

            case grabOver:
                svRight.setEnabled (false);
                setActionText ("已\n抢\n完");
                rbView.setAvailable (false);
                tvPrice.setEnabled (false);
                tvQuota.setEnabled (false);
                ivUseState.setVisibility (VISIBLE);
                ivUseState.setImageResource (R.drawable.icon_coupon_grabover);
                ivLimit.setImageResource (R.drawable.icon_double_arrow_black);
                tvLimit.setEnabled (false);
                setRightActionIsVisible (VISIBLE, GONE);
                setLimitRightPadding (getResources ().getDimensionPixelSize (R.dimen.dl_50));
                break;

            case getNow:
                svRight.setEnabled (true);
                setActionText ("立\n即\n抢");
                rbView.setAvailable (true);
                tvPrice.setEnabled (true);
                tvQuota.setEnabled (true);
                ivUseState.setVisibility (GONE);
                ivLimit.setImageResource (R.drawable.icon_double_arrow_white);
                tvLimit.setEnabled (true);
                setRightActionIsVisible (VISIBLE, GONE);
                setLimitRightPadding (getResources ().getDimensionPixelSize (R.dimen.dl_50));
                break;
        }
    }

    @Override
    protected void handleOtherUseSituation (CouponUseState state) {
        switch (state) {
            case dateOver:
                llRight.setVisibility (GONE);
                ivLimit.setImageResource (R.drawable.icon_double_arrow_black);
                tvLimit.setEnabled (false);
                rbView.setAvailable (false);
                setLimitRightPadding (getResources ().getDimensionPixelSize (R.dimen.dl_20));
                break;

            case usedNot:
                if (ivMarkup.getVisibility () == VISIBLE) {
                    llRight.setVisibility (VISIBLE);
                } else {
                    llRight.setVisibility (GONE);
                }
                ivLimit.setImageResource (R.drawable.icon_double_arrow_white);
                tvLimit.setEnabled (true);
                rbView.setAvailable (true);
                setLimitRightPadding (getResources ().getDimensionPixelSize (R.dimen.dl_20));
                break;

            case usedOver:
                setRightActionIsVisible (GONE, VISIBLE);
                ivLimit.setImageResource (R.drawable.icon_double_arrow_white);
                tvLimit.setEnabled (true);
                rbView.setAvailable (true);
                setLimitRightPadding (getResources ().getDimensionPixelSize (R.dimen.dl_30));
                break;
        }
    }

    public void setActionText (String text) {
        cftAction.setText (text);
        cftAction.setEnabled (text.equals ("立\n即\n抢"));
    }

    public void setIsChecked (boolean isChecked) {
        ivMarkup.setImageResource (isChecked ? R.drawable.icon_envelop_checknormal : R.drawable.icon_envelop_checkpress);
        //        ivMarkup.setSelected (isChecked);
    }

    /**
     * checkbox 可见
     */
    public void setMarkState (boolean isMarkState) {
        if (isMarkState) {
            svRight.setVisibility (GONE);
            ivUseState.setVisibility (GONE);
            llRight.setVisibility (VISIBLE);
            ivMarkup.setVisibility (VISIBLE);
        } else {
            ivMarkup.setVisibility (GONE);
        }
    }
}
